Type in and run the six programs presented in this chapter. Compare the output presented after each program in the text.
Basic instruction...
Back to TopWrite a program that prints the following text at the terminal:
/* Chapter 3 Exercise 2 */
#include <stdio.h>
int main (void)
{
printf ("1. In C, lowercase letters are significant.\n");
printf ("2. 'main' is where the execution begins.\n");
printf ("3. Opening and closing braces enclose program statements in a routine.\n");
printf ("4. All program statements must be terminated by a semicolon.\n");
return 0;
}
What output would you expect from the following program?
/* Chapter 3 Exercise 3 */
#include <stdio.h>
int main (void)
{
printf ("Testing....");
printf ("....1");
printf ("...2");
printf ("..1");
printf ("\n");
return 0;
}
Testing.......1...2..3 (followed by a blank line)
Back to TopWrite a program that subtracts the value of 15 from 87 and displays the result, together with an appropriate message, at the terminal.
/*Chapter 3 Exercise 4*/
#include <stdio.h>
int main (void)
{
int value1, value2, sum;
value1 = 87;
value2 = 15;
sum = value1 - value2;
printf ("%i minus %i is %i\n", value1, value2, sum);
printf ("A simple calculation using C.\n");
return 0;
}
Identify the syntactic errors in the following program. Then, type in and run the corrected program to ensure you have correctlty identified all the mistakes.
/*Chapter 3 Exercise 5*/
#include <stdio.h>
int main (Void)
(
INT sum;
/*COMPUTE RESULT
sum = 25 + 37 - 19
/*DISPLAY RESULTS //
printf ("The answer is %i\n" sum);
return 0;
}
/*Chapter 3 Exercise 5*/
#include <stdio.h>
int main (void) //Capitals matter
{ //Proper brackets
int sum; //Capitals matter
/*COMPUTE RESULT*/ //Must close this type of comment
sum = 25 + 37 - 19; //Must end with semicolon
/*DISPLAY RESULTS*/ //Must close with same comment
printf ("The answer is %i\n", sum); //Must seperate with comma
return 0;
}
What output might you expect from the following program?
/*Chapter 3 Exercise 6*/
#include <stdio.h>
int main (void)
{
int answer, result;
answer = 100;
result = answer - 10;
printf ("The result is %i\n", result + 5);
return 0;
}
The result is 95 (Followed by a blank line)
Back to Top